using System;
using BitMango;
using Data;
using UnityEngine;

public static class BlockAlarm
{
	public static bool IsValidDailyReward()
	{
		string @string = PlayerPrefs.GetString("REWARD_START", "NONE");
		string string2 = PlayerPrefs.GetString("REWARD_TIME", "NONE");
		if (@string.Equals("NONE"))
		{
			PlayerPrefs.SetString("REWARD_START", DateTime.Now.ToString());
			PlayerPrefs.Save();
			return true;
		}
		return string2.Equals("NONE") || ((DateTime.Now - DateTime.Parse(@string)).Days < 7 && (DateTime.Now - DateTime.Parse(string2)).Days > 0);
	}

	public static void RegisterAlarm()
	{
		BlockAlarm.AllUnRegister();
		BlockAlarm.RegisterRewardDailyAlarm();
		BlockAlarm.RegisterDailyAlarm();
	}

	public static void RegisterRewardDailyAlarm()
	{
		if (!DataContainer<Data.Root>.Data.options.record.notice)
		{
			return;
		}
		if (BlockAlarm.IsExpiredSevenDaysDailyReward())
		{
			return;
		}
		DateTime dateTime = DateTime.Now.AddDays(1.0);
		for (int i = 0; i < 7; i++)
		{
			if (PlayerPrefs.GetString("REWARD_" + i, "NONE").Equals("NONE"))
			{
				string title = "Block Puzzle Games";
				string message = string.Empty;
				if (i == 0)
				{
					message = string.Format("Get daily reward and fit more blocks! It has just started!", new object[0]);
				}
				else if (7 - i == 1)
				{
					message = string.Format("Get daily reward and fit more blocks! It ends today!", new object[0]);
				}
				else
				{
					message = string.Format("Get daily reward and fit more blocks! Only {0} days left!", 7 - i);
				}
				Alarm.Register(string.Format("RewardDaily_{0}", i), title, message, new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 15, 0, 0), false);
				Alarm.Register(string.Format("RewardDaily_{0}_PM", i), title, message, new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 20, 0, 0), false);
				dateTime = dateTime.AddDays(1.0);
			}
		}
	}

	public static void RegisterDailyAlarm()
	{
		if (!DataContainer<Data.Root>.Data.options.record.notice)
		{
			return;
		}
		if (!BlockAlarm.IsExpiredSevenDaysDailyReward())
		{
			return;
		}
		string title = "Block Puzzle Games";
		string[] array = new string[]
		{
			"Wake up your brain with Block Puzzle Games!",
			"Break out of everyday boredom! Play Block Puzzle Games!",
			"Outdo yourself with Block Puzzle Games!",
			"Play Block Puzzle Games! Make you smarter!"
		};
		for (int i = 1; i <= 5; i++)
		{
			int num = UnityEngine.Random.Range(0, array.Length - 1);
			string message = array[num];
			if (i == 1)
			{
				message = "Wake up your brain with Block Puzzle Games!";
			}
			Alarm.Register(string.Format("Daily_{0}", i), title, message, BlockAlarm.GetFireTickAfterDays(i, 15), false);
			Alarm.Register(string.Format("Daily_{0}_PM", i), title, message, BlockAlarm.GetFireTickAfterDays(i, 20), false);
		}
		Alarm.Register("Daily_14", title, "Your blocks are waiting for you. Come back and play now!", BlockAlarm.GetFireTickAfterDays(14, 15), false);
		Alarm.Register("Daily_14_PM", title, "Your blocks are waiting for you. Come back and play now!", BlockAlarm.GetFireTickAfterDays(14, 20), false);
	}

	private static bool IsExpiredSevenDaysDailyReward()
	{
		string @string = PlayerPrefs.GetString("REWARD_START", "NONE");
		return !(@string == "NONE") && (DateTime.Now - DateTime.Parse(@string)).Days >= 7;
	}

	private static DateTime GetFireTickAfterDays(int days, int hour)
	{
		DateTime dateTime = DateTime.Now.AddDays((double)days);
		return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, hour, 0, 0);
	}

	public static void AllUnRegister()
	{
		Alarm.AllUnregister();
	}

	private const int DAILY_ALARM_HOUR1 = 15;

	private const int DAILY_ALARM_HOUR2 = 20;
}
